from rest_framework import serializers
from .models import Grade, Student, Asset  # 导入你的 Grade 模型


# 定义序列化器（告诉 DRF 如何转换 Grade 模型）
class GradeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Grade  # 关联的模型
        fields = ['id', 'name']  # 需要返回的字段（ID 和班级名称）


class StudentSerializer(serializers.ModelSerializer):
    grade = GradeSerializer()

    class Meta:
        model = Student
        fields = ['id', 'name', 'gender', 'student_id', 'birth_date', 'grade']


class AssetSerializer(serializers.ModelSerializer):
    class Meta:
        model = Asset
        fields = ['id', 'name', 'category', 'location', 'price', 'purchase_date', 'quantity', 'remark', 'status',
                  'unit']
